// 引入路由插件
import VueRouter from "vue-router";
// 引入vue
import Vue from "vue";
// 引入路由组建
import Home from "@/pages/Home";
import Search from "@/pages/Search";
import Register from "@/pages/Register";
import Login from "@/pages/Login";
import Test from "@/pages/Test";
Vue.use(VueRouter);
// 1.保存路由原型上的push方法
const originPush = VueRouter.prototype.push;
//2. 增强push方法
VueRouter.prototype.push = function (location, okCallback, errorCallback) {
  if (okCallback === undefined && errorCallback === undefined) {
    return originPush.call(this, location).catch(() => { });
  } else {
    return originPush.call(this, location, okCallback, errorCallback);
  }
};
// 1.保存路由原型上的replace方法
const originReplace = VueRouter.prototype.replace;
//2. 增强push方法
VueRouter.prototype.replace = function (location, okCallback, errorCallback) {
  if (okCallback === undefined && errorCallback === undefined) {
    return originReplace.call(this, location).catch(() => { });
  } else {
    return originReplace.call(this, location, okCallback, errorCallback);
  }
};
export default new VueRouter({
  mode: "history",
  routes: [
    { name: "home", path: "/home", component: Home,meta:{showFoot:true} },
    { name: "search", path: "/search", component: Search,meta:{showFoot:true}},
    { name: "login", path: "/login", component: Login,meta:{showFoot:false} },
    { name: "register", path: "/register", component: Register,meta:{showFoot:false} },
    { name: "test", path: "/test", component: Test ,meta:{showFoot:true}},
    { path: "/", redirect: "/home" },
  ],
});
